//
//  LXAppointmentTableViewCell.m
//  lixing
//
//  Created by bancheng on 2022/6/25.
//

#import "LXAppointmentTableViewCell.h"
#import "LXAppointmentModel.h"
@implementation LXAppointmentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.backgroundView addCorner:10];
    [self.callPhone addCorner:3];
}

- (void)setModel:(LXAppointmentModel *)model{
    _model = model;
    
    self.timeLab.text = [NSString timestampSwitchTime:[NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"] /1000 andFormatter:@"yyyy年MM月dd日 HH:mm"];
    self.addressLab.text = model.companyAddr;
    
    self.rightTimeLab.text = [NSString timestampSwitchTime:[NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"] /1000 andFormatter:@"MM月dd"];
    self.rightTimeLab.hidden = NO;
    // 预约成功
    if ([model.status intValue] == 1) {
        self.yueImgeV.hidden = NO ;
        self.statusLab.hidden = YES;

        if ([[NSString getNowTimeTimestamp:@"yyyy-MM-dd HH:mm"] integerValue] > [NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"]) {
            self.rightTimeLab.textColor = ColorWithAAAAAA;
            self.yueImgeV.image = [UIImage imageNamed:@"订单已结束"];
        }
        else {
            self.rightTimeLab.textColor = UIColor.whiteColor;
            self.yueImgeV.image = [UIImage imageNamed:@"订单预约成功"];
        }
    }
    // 待确认
    else if ([model.status intValue] == 2) {
        self.yueImgeV.hidden = YES;
        self.statusLab.hidden = NO;
        self.rightTimeLab.hidden = YES;
        self.statusLab.text = @"待确认";
        self.statusLab.textColor = [UIColor colorWithHexString:@"#FF9A00"];
    }
    //已取消
    else if ([model.status intValue] == 3) {
        self.yueImgeV.hidden = YES;
        self.statusLab.hidden = NO;
        self.rightTimeLab.hidden = YES;
        self.statusLab.text = @"已取消";
        self.statusLab.textColor = [UIColor colorWithHexString:@"#EA545A"];
    }
    
    NSString *uName = @"-";
    if (!StringIsEmpty(model.dname)) {
        uName = model.dname;
    }
    else if (!StringIsEmpty(model.remarkName)) {
        uName = model.remarkName;
    }
    else if (!StringIsEmpty(model.nickname)) {
        uName = model.nickname;
    }
    [self.callPhone setTitle:[NSString stringWithFormat:@" 客户：%@",uName] forState:UIControlStateNormal];
    
}

@end
